package com.wjw.java.thread;

//实现线程的方式二：实现Runnable接口
public class MyRunnable {
    public static void main(String[] args) {
        Dog dog = new Dog();
        //不能直接调用run(),直接调用就没有启动子线程,相当于main线程执行一个普通方法
        //此时是串行执行,代码会阻塞,等run方法中的代码执行完毕,才会往下执行代码
        //dog.run();
        Thread t1 = new Thread(dog);
        t1.start();
    }
}
class Dog implements Runnable{

    int times = 0;//记录循环次数

    @Override
    public void run() {
        //获取线程的名称
        String threadName = Thread.currentThread().getName();
        while (true){
            System.out.println("线程:"+threadName+",旺财汪汪叫..." + (++times));
            //ctrl+alt+t是try...catch的快捷键
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            if(times == 80){//结束循环
                break;
            }
        }//while
    }
}